IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_user]') AND type in (N'U')) DROP TABLE [dbo].[sys_user];
CREATE TABLE [dbo].[sys_user](
                                 id  NOT NULL,
                                 user_name VARCHAR(32),
    user_code VARCHAR(32),
    user_mobile VARCHAR(16),
    login_name VARCHAR(32),
    email VARCHAR(64),
    password VARCHAR(255),
    salt VARCHAR(64),
    avatar VARCHAR(255),
    open_id VARCHAR(128),
    dingtalk_id VARCHAR(128),
    wxwork_user_id VARCHAR(128),
    tenant_id ,
    create_user ,
    update_user ,
    create_time DATETIME,
    update_time DATETIME,
    is_delete INT NOT NULL,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '系统用户表', 'SCHEMA', dbo, 'table', sys_user, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_user, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '用户名称;用户名称', 'SCHEMA', dbo, 'table', sys_user, 'column', user_name;
EXEC sp_addextendedproperty 'MS_Description', '用户编号;用户编号', 'SCHEMA', dbo, 'table', sys_user, 'column', user_code;
EXEC sp_addextendedproperty 'MS_Description', '电话;电话', 'SCHEMA', dbo, 'table', sys_user, 'column', user_mobile;
EXEC sp_addextendedproperty 'MS_Description', '登录账号;登录账号', 'SCHEMA', dbo, 'table', sys_user, 'column', login_name;
EXEC sp_addextendedproperty 'MS_Description', '邮箱;邮箱', 'SCHEMA', dbo, 'table', sys_user, 'column', email;
EXEC sp_addextendedproperty 'MS_Description', '密码;密码', 'SCHEMA', dbo, 'table', sys_user, 'column', password;
EXEC sp_addextendedproperty 'MS_Description', 'salt;salt', 'SCHEMA', dbo, 'table', sys_user, 'column', salt;
EXEC sp_addextendedproperty 'MS_Description', '头像;头像', 'SCHEMA', dbo, 'table', sys_user, 'column', avatar;
EXEC sp_addextendedproperty 'MS_Description', '微信openid;微信openid', 'SCHEMA', dbo, 'table', sys_user, 'column', open_id;
EXEC sp_addextendedproperty 'MS_Description', '钉钉ID;钉钉ID', 'SCHEMA', dbo, 'table', sys_user, 'column', dingtalk_id;
EXEC sp_addextendedproperty 'MS_Description', '企业微信用户ID;企业微信用户ID', 'SCHEMA', dbo, 'table', sys_user, 'column', wxwork_user_id;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_user, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_user, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_user, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_user, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_user, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_user, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_org]') AND type in (N'U')) DROP TABLE [dbo].[sys_org];
CREATE TABLE [dbo].[sys_org](
                                id bigint NOT NULL,
                                org_name VARCHAR(64),
    org_code VARCHAR(32),
    parent_id bigint(255),
    org_path VARCHAR(900),
    org_type INT,
    leader VARCHAR(16),
    contact_tele VARCHAR(255),
    tenant_id bigint,
    create_user bigint,
    update_user bigint,
    create_time DATETIME,
    update_time DATETIME,
    is_delete INT NOT NULL,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '组织信息表', 'SCHEMA', dbo, 'table', sys_org, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_org, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '组织名称;组织名称', 'SCHEMA', dbo, 'table', sys_org, 'column', org_name;
EXEC sp_addextendedproperty 'MS_Description', '组织编号;组织编号', 'SCHEMA', dbo, 'table', sys_org, 'column', org_code;
EXEC sp_addextendedproperty 'MS_Description', '上级组织ID;上级组织ID', 'SCHEMA', dbo, 'table', sys_org, 'column', parent_id;
EXEC sp_addextendedproperty 'MS_Description', '组织路径;组织路径', 'SCHEMA', dbo, 'table', sys_org, 'column', org_path;
EXEC sp_addextendedproperty 'MS_Description', '组织类型;组织类型', 'SCHEMA', dbo, 'table', sys_org, 'column', org_type;
EXEC sp_addextendedproperty 'MS_Description', '负责人;负责人', 'SCHEMA', dbo, 'table', sys_org, 'column', leader;
EXEC sp_addextendedproperty 'MS_Description', '联系电话;联系电话', 'SCHEMA', dbo, 'table', sys_org, 'column', contact_tele;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_org, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_org, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_org, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_org, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_org, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_org, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_dept]') AND type in (N'U')) DROP TABLE [dbo].[sys_dept];
CREATE TABLE [dbo].[sys_dept](
                                 id  NOT NULL,
                                 dept_name VARCHAR(64),
    dept_code VARCHAR(16),
    parent_id ,
    org_id ,
    dept_path VARCHAR(900),
    tenant_id bigint,
    create_user bigint,
    update_user bigint,
    create_time DATETIME,
    update_time DATETIME,
    is_delete INT NOT NULL,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '部门信息表', 'SCHEMA', dbo, 'table', sys_dept, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_dept, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '部门名称;部门名称', 'SCHEMA', dbo, 'table', sys_dept, 'column', dept_name;
EXEC sp_addextendedproperty 'MS_Description', '部门编号;部门编号', 'SCHEMA', dbo, 'table', sys_dept, 'column', dept_code;
EXEC sp_addextendedproperty 'MS_Description', '上级部门ID;上级部门ID', 'SCHEMA', dbo, 'table', sys_dept, 'column', parent_id;
EXEC sp_addextendedproperty 'MS_Description', '组织ID;组织ID', 'SCHEMA', dbo, 'table', sys_dept, 'column', org_id;
EXEC sp_addextendedproperty 'MS_Description', '部门路径;部门路径', 'SCHEMA', dbo, 'table', sys_dept, 'column', dept_path;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_dept, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_dept, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_dept, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_dept, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_dept, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_dept, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_dept_user]') AND type in (N'U')) DROP TABLE [dbo].[sys_dept_user];
CREATE TABLE [dbo].[sys_dept_user](
                                      id bigint NOT NULL,
                                      dept_id ,
                                      user_id ,
                                      user_role INT,
                                      work_num ,
                                      tenant_id bigint,
                                      create_user bigint,
                                      update_user bigint,
                                      create_time DATETIME,
                                      update_time DATETIME,
                                      is_delete INT NOT NULL,
                                      PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '部门用户表', 'SCHEMA', dbo, 'table', sys_dept_user, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '部门ID;部门ID', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', dept_id;
EXEC sp_addextendedproperty 'MS_Description', '用户ID;用户ID', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', user_id;
EXEC sp_addextendedproperty 'MS_Description', '用户角色;用户角色 1=部门负责人；2=普通成员；', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', user_role;
EXEC sp_addextendedproperty 'MS_Description', '工号;工号', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', work_num;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_dept_user, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_user_identity]') AND type in (N'U')) DROP TABLE [dbo].[sys_user_identity];
CREATE TABLE [dbo].[sys_user_identity](
                                          id bigint NOT NULL,
                                          user_id ,
                                          identity_id ,
                                          identity_type INT,
                                          identity_org_id ,
                                          identity_dept_id ,
                                          identity_role_id ,
                                          tenant_id bigint,
                                          create_user bigint,
                                          update_user bigint,
                                          create_time DATETIME,
                                          update_time DATETIME,
                                          is_delete INT NOT NULL,
                                          PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '用户身份表', 'SCHEMA', dbo, 'table', sys_user_identity, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '用户ID', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', user_id;
EXEC sp_addextendedproperty 'MS_Description', '身份表ID;身份表ID', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', identity_id;
EXEC sp_addextendedproperty 'MS_Description', '身份类型;身份类型 1=B端用户；2=C端用户；3=管理端用户', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', identity_type;
EXEC sp_addextendedproperty 'MS_Description', '机构ID;机构ID', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', identity_org_id;
EXEC sp_addextendedproperty 'MS_Description', '部门ID;部门ID', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', identity_dept_id;
EXEC sp_addextendedproperty 'MS_Description', '身份角色ID;身份角色ID', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', identity_role_id;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_user_identity, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_identity_role]') AND type in (N'U')) DROP TABLE [dbo].[sys_identity_role];
CREATE TABLE [dbo].[sys_identity_role](
                                          id bigint NOT NULL,
                                          role_name VARCHAR(32),
    role_code VARCHAR(16),
    order_no INT,
    identity_org_id ,
    is_system INT NOT NULL DEFAULT  0,
    remark VARCHAR(255),
    tenant_id bigint,
    create_user bigint,
    update_user bigint,
    create_time DATETIME,
    update_time DATETIME,
    is_delete INT NOT NULL,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '用户角色表', 'SCHEMA', dbo, 'table', sys_identity_role, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '角色名称;角色名称', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', role_name;
EXEC sp_addextendedproperty 'MS_Description', '角色编号;角色编号', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', role_code;
EXEC sp_addextendedproperty 'MS_Description', '排序编号;排序编号', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', order_no;
EXEC sp_addextendedproperty 'MS_Description', '所属机构;所属机构', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', identity_org_id;
EXEC sp_addextendedproperty 'MS_Description', '是否系统内置;是否系统内置 1=是；0=否', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', is_system;
EXEC sp_addextendedproperty 'MS_Description', '备注;备注', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', remark;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_identity_role, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_identity_role_menu]') AND type in (N'U')) DROP TABLE [dbo].[sys_identity_role_menu];
CREATE TABLE [dbo].[sys_identity_role_menu](
                                               id bigint NOT NULL,
                                               role_id ,
                                               menu_id ,
                                               identity_id ,
                                               tenant_id bigint,
                                               create_user bigint,
                                               update_user bigint,
                                               create_time DATETIME,
                                               update_time DATETIME,
                                               is_delete INT NOT NULL,
                                               PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '系统角色菜单表', 'SCHEMA', dbo, 'table', sys_identity_role_menu, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '角色ID;角色ID', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', role_id;
EXEC sp_addextendedproperty 'MS_Description', '菜单ID;菜单ID', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', menu_id;
EXEC sp_addextendedproperty 'MS_Description', '身份ID;身份ID', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', identity_id;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_identity_role_menu, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_menu]') AND type in (N'U')) DROP TABLE [dbo].[sys_menu];
CREATE TABLE [dbo].[sys_menu](
                                 id  NOT NULL,
                                 menu_name VARCHAR(64),
    parent_id ,
    url TEXT(255),
    menu_type INT,
    tenant_id bigint,
    create_user bigint,
    update_user bigint,
    create_time DATETIME,
    update_time DATETIME,
    is_delete INT NOT NULL,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '系统菜单表', 'SCHEMA', dbo, 'table', sys_menu, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_menu, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '菜单名称;菜单名称', 'SCHEMA', dbo, 'table', sys_menu, 'column', menu_name;
EXEC sp_addextendedproperty 'MS_Description', '上级ID;上级ID', 'SCHEMA', dbo, 'table', sys_menu, 'column', parent_id;
EXEC sp_addextendedproperty 'MS_Description', '路由地址;路由地址', 'SCHEMA', dbo, 'table', sys_menu, 'column', url;
EXEC sp_addextendedproperty 'MS_Description', '菜单类型;菜单类型 1=系统菜单；2=外部菜单', 'SCHEMA', dbo, 'table', sys_menu, 'column', menu_type;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_menu, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_menu, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_menu, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_menu, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_menu, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_menu, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_config]') AND type in (N'U')) DROP TABLE [dbo].[sys_config];
CREATE TABLE [dbo].[sys_config](
                                   id  NOT NULL,
                                   config_name VARCHAR(255) NOT NULL,
    config_value VARCHAR(900),
    config_desc VARCHAR(255),
    tenant_id bigint,
    create_user bigint,
    update_user bigint,
    create_time DATETIME,
    update_time DATETIME,
    is_delete INT NOT NULL,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '系统配置信息表', 'SCHEMA', dbo, 'table', sys_config, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_config, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '配置名称;配置名称（唯一）', 'SCHEMA', dbo, 'table', sys_config, 'column', config_name;
EXEC sp_addextendedproperty 'MS_Description', '配置项值;配置项值', 'SCHEMA', dbo, 'table', sys_config, 'column', config_value;
EXEC sp_addextendedproperty 'MS_Description', '配置描述;配置描述', 'SCHEMA', dbo, 'table', sys_config, 'column', config_desc;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_config, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_config, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_config, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_config, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_config, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_config, 'column', is_delete;


CREATE UNIQUE INDEX INX_UK_CONFIG_NAME ON sys_config(config_name);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_dict]') AND type in (N'U')) DROP TABLE [dbo].[sys_dict];
CREATE TABLE [dbo].[sys_dict](
                                 id  NOT NULL,
                                 dict_name VARCHAR(255),
    dict_value VARCHAR(900),
    dict_desc VARCHAR(255),
    order_no INT,
    tenant_id bigint,
    create_user bigint,
    update_user bigint,
    create_time DATETIME,
    update_time DATETIME,
    is_delete INT NOT NULL,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '系统字典表', 'SCHEMA', dbo, 'table', sys_dict, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_dict, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '字典名称;字典名称', 'SCHEMA', dbo, 'table', sys_dict, 'column', dict_name;
EXEC sp_addextendedproperty 'MS_Description', '字段值;字段值', 'SCHEMA', dbo, 'table', sys_dict, 'column', dict_value;
EXEC sp_addextendedproperty 'MS_Description', '描述;描述', 'SCHEMA', dbo, 'table', sys_dict, 'column', dict_desc;
EXEC sp_addextendedproperty 'MS_Description', '序号;序号', 'SCHEMA', dbo, 'table', sys_dict, 'column', order_no;
EXEC sp_addextendedproperty 'MS_Description', '租户ID;租户ID', 'SCHEMA', dbo, 'table', sys_dict, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_dict, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_dict, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_dict, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新时间;更新时间', 'SCHEMA', dbo, 'table', sys_dict, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_dict, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[app_base]') AND type in (N'U')) DROP TABLE [dbo].[app_base];
CREATE TABLE [dbo].[app_base](
    id VARCHAR(32) NOT NULL,
    app_name VARCHAR(90),
    app_path VARCHAR(255),
    db_prefix VARCHAR(32),
    package_path VARCHAR(255),
    app_status TINYINT,
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '应用基础表', 'SCHEMA', dbo, 'table', app_base, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', app_base, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '应用名称;应用名称', 'SCHEMA', dbo, 'table', app_base, 'column', app_name;
EXEC sp_addextendedproperty 'MS_Description', '应用路径（用于自动代码生成的工程路径）;应用路径（用于自动代码生成的工程路径）', 'SCHEMA', dbo, 'table', app_base, 'column', app_path;
EXEC sp_addextendedproperty 'MS_Description', '数据库表前缀;数据库表前缀', 'SCHEMA', dbo, 'table', app_base, 'column', db_prefix;
EXEC sp_addextendedproperty 'MS_Description', '包名路径;包名路径', 'SCHEMA', dbo, 'table', app_base, 'column', package_path;
EXEC sp_addextendedproperty 'MS_Description', '状态 0=正常；1=失效;状态 0=正常；1=失效', 'SCHEMA', dbo, 'table', app_base, 'column', app_status;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', app_base, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', app_base, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', app_base, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', app_base, 'column', update_by;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[form_base]') AND type in (N'U')) DROP TABLE [dbo].[form_base];
CREATE TABLE [dbo].[form_base](
    id VARCHAR(32) NOT NULL,
    form_name VARCHAR(90),
    table_name VARCHAR(64),
    app_id VARCHAR(32),
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '表单基础信息', 'SCHEMA', dbo, 'table', form_base, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', form_base, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '表单名称;表单名称', 'SCHEMA', dbo, 'table', form_base, 'column', form_name;
EXEC sp_addextendedproperty 'MS_Description', '数据库表名;数据库表名', 'SCHEMA', dbo, 'table', form_base, 'column', table_name;
EXEC sp_addextendedproperty 'MS_Description', '应用ID;应用ID', 'SCHEMA', dbo, 'table', form_base, 'column', app_id;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', form_base, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', form_base, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', form_base, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', form_base, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', form_base, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[form_field]') AND type in (N'U')) DROP TABLE [dbo].[form_field];
CREATE TABLE [dbo].[form_field](
    id VARCHAR(32) NOT NULL,
    app_id VARCHAR(32),
    form_id VARCHAR(32),
    field_name VARCHAR(32) NOT NULL,
    show_name VARCHAR(90),
    db_type VARCHAR(32),
    db_length INT,
    db_decimal INT,
    source_id VARCHAR(32),
    html_type TINYINT,
    is_multiple VARCHAR(1) NOT NULL DEFAULT  '0',
    prefix VARCHAR(32),
    suffix VARCHAR(32),
    format_pattern VARCHAR(32),
    regular VARCHAR(255),
    regular_msg VARCHAR(255),
    next_field VARCHAR(32),
    is_required VARCHAR(1) NOT NULL DEFAULT  '0',
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '表单字段信息', 'SCHEMA', dbo, 'table', form_field, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', form_field, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '应用ID;应用ID', 'SCHEMA', dbo, 'table', form_field, 'column', app_id;
EXEC sp_addextendedproperty 'MS_Description', '表单ID;表单ID', 'SCHEMA', dbo, 'table', form_field, 'column', form_id;
EXEC sp_addextendedproperty 'MS_Description', '字段名称;字段名称', 'SCHEMA', dbo, 'table', form_field, 'column', field_name;
EXEC sp_addextendedproperty 'MS_Description', '显示名称;显示名称', 'SCHEMA', dbo, 'table', form_field, 'column', show_name;
EXEC sp_addextendedproperty 'MS_Description', '数据库类型;数据库类型', 'SCHEMA', dbo, 'table', form_field, 'column', db_type;
EXEC sp_addextendedproperty 'MS_Description', '字段长度', 'SCHEMA', dbo, 'table', form_field, 'column', db_length;
EXEC sp_addextendedproperty 'MS_Description', '小数点位数;小数点位数', 'SCHEMA', dbo, 'table', form_field, 'column', db_decimal;
EXEC sp_addextendedproperty 'MS_Description', '数据源ID;数据源ID', 'SCHEMA', dbo, 'table', form_field, 'column', source_id;
EXEC sp_addextendedproperty 'MS_Description', '显示类型;显示类型，来源数据字典', 'SCHEMA', dbo, 'table', form_field, 'column', html_type;
EXEC sp_addextendedproperty 'MS_Description', '是否多选;是否多选 1=是；0=否', 'SCHEMA', dbo, 'table', form_field, 'column', is_multiple;
EXEC sp_addextendedproperty 'MS_Description', '前缀;前缀', 'SCHEMA', dbo, 'table', form_field, 'column', prefix;
EXEC sp_addextendedproperty 'MS_Description', '后缀;后缀', 'SCHEMA', dbo, 'table', form_field, 'column', suffix;
EXEC sp_addextendedproperty 'MS_Description', '数据格式;数据格式', 'SCHEMA', dbo, 'table', form_field, 'column', format_pattern;
EXEC sp_addextendedproperty 'MS_Description', '正则方法;正则方法', 'SCHEMA', dbo, 'table', form_field, 'column', regular;
EXEC sp_addextendedproperty 'MS_Description', '正则错误提示;正则错误提示', 'SCHEMA', dbo, 'table', form_field, 'column', regular_msg;
EXEC sp_addextendedproperty 'MS_Description', '关联下级ID;关联下级ID，用于下拉级联操作', 'SCHEMA', dbo, 'table', form_field, 'column', next_field;
EXEC sp_addextendedproperty 'MS_Description', '是否必填;是否必填 1=是；0=否', 'SCHEMA', dbo, 'table', form_field, 'column', is_required;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', form_field, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', form_field, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', form_field, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', form_field, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', form_field, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[form_field_option]') AND type in (N'U')) DROP TABLE [dbo].[form_field_option];
CREATE TABLE [dbo].[form_field_option](
    id VARCHAR(32) NOT NULL,
    form_id VARCHAR(32),
    field_id VARCHAR(32),
    option_value VARCHAR(32),
    option_text VARCHAR(90),
    seq_no INT,
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '下拉字段自定义字典表', 'SCHEMA', dbo, 'table', form_field_option, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', form_field_option, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '表单ID;表单ID', 'SCHEMA', dbo, 'table', form_field_option, 'column', form_id;
EXEC sp_addextendedproperty 'MS_Description', '字段ID;字段ID', 'SCHEMA', dbo, 'table', form_field_option, 'column', field_id;
EXEC sp_addextendedproperty 'MS_Description', '字典值;字典值', 'SCHEMA', dbo, 'table', form_field_option, 'column', option_value;
EXEC sp_addextendedproperty 'MS_Description', '显示文本;显示文本', 'SCHEMA', dbo, 'table', form_field_option, 'column', option_text;
EXEC sp_addextendedproperty 'MS_Description', '序号;序号', 'SCHEMA', dbo, 'table', form_field_option, 'column', seq_no;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', form_field_option, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', form_field_option, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', form_field_option, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', form_field_option, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', form_field_option, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[form_layout]') AND type in (N'U')) DROP TABLE [dbo].[form_layout];
CREATE TABLE [dbo].[form_layout](
    id VARCHAR(32) NOT NULL,
    app_id VARCHAR(32),
    form_id VARCHAR(32),
    layout_name VARCHAR(90),
    client_type TINYINT,
    layout_type TINYINT,
    layout_json TEXT,
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '表单布局表', 'SCHEMA', dbo, 'table', form_layout, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', form_layout, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '应用ID;应用ID', 'SCHEMA', dbo, 'table', form_layout, 'column', app_id;
EXEC sp_addextendedproperty 'MS_Description', '表单ID;表单ID', 'SCHEMA', dbo, 'table', form_layout, 'column', form_id;
EXEC sp_addextendedproperty 'MS_Description', '布局名称;布局名称', 'SCHEMA', dbo, 'table', form_layout, 'column', layout_name;
EXEC sp_addextendedproperty 'MS_Description', '模板类型;模板类型（0：PC端，1：移动端）', 'SCHEMA', dbo, 'table', form_layout, 'column', client_type;
EXEC sp_addextendedproperty 'MS_Description', '布局类型;布局类型 DD:LAYOUT_TYPE', 'SCHEMA', dbo, 'table', form_layout, 'column', layout_type;
EXEC sp_addextendedproperty 'MS_Description', '布局JSON;布局JSON', 'SCHEMA', dbo, 'table', form_layout, 'column', layout_json;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', form_layout, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', form_layout, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', form_layout, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', form_layout, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', form_layout, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[form_link]') AND type in (N'U')) DROP TABLE [dbo].[form_link];
CREATE TABLE [dbo].[form_link](
    id VARCHAR(32) NOT NULL,
    source_id VARCHAR(32),
    target_id VARCHAR(32),
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '表单关联关系表', 'SCHEMA', dbo, 'table', form_link, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', form_link, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '源ID;源ID', 'SCHEMA', dbo, 'table', form_link, 'column', source_id;
EXEC sp_addextendedproperty 'MS_Description', '目标ID;目标ID', 'SCHEMA', dbo, 'table', form_link, 'column', target_id;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', form_link, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', form_link, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', form_link, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', form_link, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', form_link, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[serial_number]') AND type in (N'U')) DROP TABLE [dbo].[serial_number];
CREATE TABLE [dbo].[serial_number](
    id VARCHAR(32) NOT NULL,
    form_id VARCHAR(32),
    field_id VARCHAR(32),
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '流水号配置表', 'SCHEMA', dbo, 'table', serial_number, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID', 'SCHEMA', dbo, 'table', serial_number, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '表单ID;表单ID', 'SCHEMA', dbo, 'table', serial_number, 'column', form_id;
EXEC sp_addextendedproperty 'MS_Description', '字段ID;字段ID', 'SCHEMA', dbo, 'table', serial_number, 'column', field_id;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', serial_number, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', serial_number, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', serial_number, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', serial_number, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', serial_number, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[serial_number_detail]') AND type in (N'U')) DROP TABLE [dbo].[serial_number_detail];
CREATE TABLE [dbo].[serial_number_detail](
    id VARCHAR(32) NOT NULL,
    serial_id VARCHAR(32),
    serial_type VARCHAR(90),
    serial_value VARCHAR(90),
    alone_serial VARCHAR(1) NOT NULL DEFAULT  '0',
    seq_no INT,
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '流水号配置明细表', 'SCHEMA', dbo, 'table', serial_number_detail, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '流水号配置ID;流水号配置ID', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', serial_id;
EXEC sp_addextendedproperty 'MS_Description', '配置类型;配置类型', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', serial_type;
EXEC sp_addextendedproperty 'MS_Description', '配置值;配置值', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', serial_value;
EXEC sp_addextendedproperty 'MS_Description', '单独流水;是否单独流水 1=是；0=否', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', alone_serial;
EXEC sp_addextendedproperty 'MS_Description', '序号;序号', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', seq_no;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', serial_number_detail, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_param]') AND type in (N'U')) DROP TABLE [dbo].[sys_param];
CREATE TABLE [dbo].[sys_param](
                                  id INT IDENTITY(1,1)
    param_name VARCHAR(90),
    param_value VARCHAR(900),
    ext_value VARCHAR(900),
    create_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    create_by VARCHAR(32),
    update_time DATETIME NOT NULL DEFAULT  CURRENT_TIMESTAMP,
    update_by VARCHAR(32),
    is_delete TINYINT NOT NULL DEFAULT  0,
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '系统参数表', 'SCHEMA', dbo, 'table', sys_param, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键ID;主键ID', 'SCHEMA', dbo, 'table', sys_param, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '参数名称;参数名称', 'SCHEMA', dbo, 'table', sys_param, 'column', param_name;
EXEC sp_addextendedproperty 'MS_Description', '参数值;参数值', 'SCHEMA', dbo, 'table', sys_param, 'column', param_value;
EXEC sp_addextendedproperty 'MS_Description', '扩展值;扩展值', 'SCHEMA', dbo, 'table', sys_param, 'column', ext_value;
EXEC sp_addextendedproperty 'MS_Description', '创建时间;创建时间', 'SCHEMA', dbo, 'table', sys_param, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '创建人;创建人', 'SCHEMA', dbo, 'table', sys_param, 'column', create_by;
EXEC sp_addextendedproperty 'MS_Description', '最后更新时间;最后更新时间', 'SCHEMA', dbo, 'table', sys_param, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人;更新人', 'SCHEMA', dbo, 'table', sys_param, 'column', update_by;
EXEC sp_addextendedproperty 'MS_Description', '是否删除;是否删除 0=否；1=是，默认0', 'SCHEMA', dbo, 'table', sys_param, 'column', is_delete;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sys_region]') AND type in (N'U')) DROP TABLE [dbo].[sys_region];
CREATE TABLE [dbo].[sys_region](
                                   id  NOT NULL,
                                   tenant_id  NOT NULL DEFAULT  -1,
                                   create_user ,
                                   create_org_id ,
                                   create_time DATETIME,
                                   update_user ,
                                   update_time DATETIME,
                                   deleted INT NOT NULL DEFAULT  0,
                                   region_name VARCHAR(255),
    region_code VARCHAR(255),
    parent_id ,
    level INT,
    type INT,
    region_path VARCHAR(255),
    sort_no INT,
    region_path_name VARCHAR(255),
    PRIMARY KEY (id)
    );

EXEC sp_addextendedproperty 'MS_Description', '系统区域表', 'SCHEMA', dbo, 'table', sys_region, null, null;
EXEC sp_addextendedproperty 'MS_Description', '主键id', 'SCHEMA', dbo, 'table', sys_region, 'column', id;
EXEC sp_addextendedproperty 'MS_Description', '租户号', 'SCHEMA', dbo, 'table', sys_region, 'column', tenant_id;
EXEC sp_addextendedproperty 'MS_Description', '创建人', 'SCHEMA', dbo, 'table', sys_region, 'column', create_user;
EXEC sp_addextendedproperty 'MS_Description', '创建人组织', 'SCHEMA', dbo, 'table', sys_region, 'column', create_org_id;
EXEC sp_addextendedproperty 'MS_Description', '创建时间', 'SCHEMA', dbo, 'table', sys_region, 'column', create_time;
EXEC sp_addextendedproperty 'MS_Description', '更新人', 'SCHEMA', dbo, 'table', sys_region, 'column', update_user;
EXEC sp_addextendedproperty 'MS_Description', '更新时间', 'SCHEMA', dbo, 'table', sys_region, 'column', update_time;
EXEC sp_addextendedproperty 'MS_Description', '是否删除 0=否 1=是', 'SCHEMA', dbo, 'table', sys_region, 'column', deleted;
EXEC sp_addextendedproperty 'MS_Description', '区域名称', 'SCHEMA', dbo, 'table', sys_region, 'column', region_name;
EXEC sp_addextendedproperty 'MS_Description', '区域code', 'SCHEMA', dbo, 'table', sys_region, 'column', region_code;
EXEC sp_addextendedproperty 'MS_Description', '父节点id', 'SCHEMA', dbo, 'table', sys_region, 'column', parent_id;
EXEC sp_addextendedproperty 'MS_Description', '层级', 'SCHEMA', dbo, 'table', sys_region, 'column', level;
EXEC sp_addextendedproperty 'MS_Description', '1=省2市3区', 'SCHEMA', dbo, 'table', sys_region, 'column', type;
EXEC sp_addextendedproperty 'MS_Description', '路径path //', 'SCHEMA', dbo, 'table', sys_region, 'column', region_path;
EXEC sp_addextendedproperty 'MS_Description', '排序', 'SCHEMA', dbo, 'table', sys_region, 'column', sort_no;
EXEC sp_addextendedproperty 'MS_Description', '路径path名称 //', 'SCHEMA', dbo, 'table', sys_region, 'column', region_path_name;

